package com.chenjinlong.servlet;

import com.chenjinlong.until.DBUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

@WebServlet("/finish")
public class FinishServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1、获取用户点击事项的id
        req.setCharacterEncoding("utf-8");
        String id = req.getParameter("id");
        //进行数据库表的更新
        try (Connection c = DBUtil.connection()) {
            String sql = "UPDATE item set state = 1 WHERE id=?";
            try (PreparedStatement s = c.prepareStatement(sql)) {
                s.setString(1, id);

                s.executeUpdate();
            }
        } catch (SQLException exc) {
            throw new ServletException(exc);
        }
    }
}
